﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace EWS
{
    public partial class NewBedDialog : Form
    {
        private int bedNumber;
        private int pkNurse;
        private int pkDoctor;

        public NewBedDialog(int wardNumber)
        {
            InitializeComponent();

            // stationsnummer kommt von gui! in dem auswahlfeld für die station
            // ist somit die richtige stationsnummer (erste stelle) für die 
            // bettnummer
            int maximum = (wardNumber * 100) + 63;
            int minimum = (wardNumber * 100) + 1;
            this.numericUpDownBedNumber.Maximum = new decimal(new int[] {
            maximum,  
            0,
            0,
            0});
            this.numericUpDownBedNumber.Minimum = new decimal(new int[] {
            minimum,
            0,
            0,
            0});

            // hole die aktuellen listen mit schwestern/doktoren
            DBConnection conn = DBConnection.getInstance();
            List<KeyValuePair<int, string>> nursesList = conn.getNurses();
            List<KeyValuePair<int, string>> doctorsList = conn.getDoctors();
            
            // binde die daten an die comboxen
            // (Value entsptricht dem Namen (string), Key dem Primärschlüssel (int)
            
            // für schwestern combobox
            comboBoxNurse.DataSource = new BindingSource(nursesList, null);
            comboBoxNurse.DisplayMember = "Value";
            comboBoxNurse.ValueMember = "Key";
            
            // für doktoren combobox
            comboBoxDoctor.DataSource = new BindingSource(doctorsList, null);
            comboBoxDoctor.DisplayMember = "Value";
            comboBoxDoctor.ValueMember = "Key";
        }

        public int BedNumber
        {
            get { return bedNumber; }
        }

        public int PkNurse
        {
            get { return pkNurse; }
        }

        public int PkDoctor
        {
            get { return pkDoctor; }
        }

        private void numericUpDownBedNumber_ValueChanged(object sender, EventArgs e)
        {
            bedNumber = (int) numericUpDownBedNumber.Value;
        }

        private void comboBoxNurse_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Get the selected item in the combobox
            KeyValuePair<int, string> selectedNurse = (KeyValuePair<int, string>) comboBoxNurse.SelectedItem;
            pkNurse = selectedNurse.Key;
        }

        private void comboBoxDoctor_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Get the selected item in the combobox
            KeyValuePair<int, string> selectedDoctor = (KeyValuePair<int, string>)comboBoxDoctor.SelectedItem;
            pkDoctor = selectedDoctor.Key;
        }
    }
}
